<?php

namespace app\api\controller;

use app\aiQuestion\logic\aiQuestionLogic;
use app\api\basic\BaseController;
use plugin\saiadmin\basic\OpenController;
use app\api\annotation\LoginRequired;
use support\Request;


class AiQuestionController extends OpenController {
     protected $userInfo;

    /**
     * 当前登陆管理员ID
     */
    protected $userId;

    /**
     * 当前登陆管理员账号
     */
    protected $userName;
    public function __construct()
    {   
        parent::__construct();
        $this->userId=request()->userId;
        $this->userName=request()->userName;
        $this->userInfo=request()->userInfo;
    }

    /**
     * 随机获取Ai问题
     */
    #[LoginRequired(required:false)]
    public  function  getAiQuestion(Request $request){
        $param = $request->more([
            ['lang_code','zh'],
        ]);
        $aiquestion = new aiQuestionLogic();
        $data = $aiquestion->where(['lang_code'=>$param['lang_code']])
            ->field('question_id,question_title')
            ->orderRand()->limit(3)->select();
        return $this->success(['data'=>$data]);
    }

    /**
     * 通过问题返回答案
     */
    #[LoginRequired(required:false)]
    public  function  getContent(Request $request){
        $param = $request->more([
            ['lang_code','zh'],
            ['question_id',0],
        ]);
        $aiquestion = new aiQuestionLogic();
        $data = $aiquestion->where(['lang_code'=>$param['lang_code'],'question_id'=>$param['question_id']])
            ->field('question_id,question_content')
            ->find();
        return $this->success(['data'=>$data]);

    }




}